﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Comm;
using System.Xml;

public partial class Web_Admin_SiteInfo_web_site : AdminPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.CheckPopedomInfoRedirect(1005, 1);
        but_save.Enabled = base.CheckPopedomInfo(1005, 4);
        if (!IsPostBack)
        {
            loadData();
        }
    }

    /// <summary>
    /// 加载数据
    /// </summary>
    private void loadData()
    {
        XmlDocument doc = XMLHelper.xmlDoc(Server.MapPath("/App_Data/SiteInfo.xml"));
        txt_Company.Text = doc.DocumentElement["CompanyName"].InnerText;
        txt_Copyright.Text = doc.DocumentElement["CopyRight"].InnerText;
        txt_QQ.Text = doc.DocumentElement["QQ"].InnerText;
        txt_MSN.Text = doc.DocumentElement["MSN"].InnerText;
        txt_Email.Text = doc.DocumentElement["Email"].InnerText;
        txt_Password.Text = doc.DocumentElement["Password"].InnerText;
        txt_SMTP.Text = doc.DocumentElement["SMTP"].InnerText;
        chk_ShareEnabled.Checked = bool.Parse(doc.DocumentElement["ShareEnabled"].InnerText);
    }

    /// <summary>
    /// 保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void but_save_Click(object sender, EventArgs e)
    {
        string company = txt_Company.Text.Trim();
        string copyright = txt_Copyright.Text.Trim();
        string qq = txt_QQ.Text.Trim();
        string msn = txt_MSN.Text.Trim();
        string email = txt_Email.Text.Trim();
        string password = txt_Password.Text.Trim();
        string smtp = txt_SMTP.Text.Trim();
        string shareenabled = chk_ShareEnabled.Checked.ToString();

        try
        {
            XmlDocument doc = XMLHelper.xmlDoc(Server.MapPath("/App_Data/SiteInfo.xml"));
            doc.DocumentElement["CompanyName"].InnerText = company;
            doc.DocumentElement["CopyRight"].InnerText = copyright;
            doc.DocumentElement["QQ"].InnerText = qq;
            doc.DocumentElement["MSN"].InnerText = msn;
            doc.DocumentElement["Email"].InnerText = email;
            doc.DocumentElement["Password"].InnerText = password;
            doc.DocumentElement["SMTP"].InnerText = smtp;
            doc.DocumentElement["ShareEnabled"].InnerText = shareenabled;
            doc.Save(Server.MapPath("/App_Data/SiteInfo.xml"));
        }
        catch
        {
            MessageBox.Show("修改失败");
        }
        MessageBox.Show("修改成功");
    }
}
